package com.android.audio;

import java.io.File;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Environment;

public class AudioPlayer {
	
	private MediaPlayer mPlayerSD;
	private String path;
	
	public AudioPlayer(String filname){
		mPlayerSD = new MediaPlayer();
		path = SetPath(filname);
	}
	
	private String SetPath(String filname){
		return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + filname + ".mp4";
	}

	public void playFromSD(){
		try {
       		mPlayerSD.reset();
       		mPlayerSD.setDataSource(path);
       		mPlayerSD.setAudioStreamType(AudioManager.STREAM_MUSIC);
       		mPlayerSD.prepare();
       		mPlayerSD.start();
			} catch (Exception e) {
				e.printStackTrace();
			}	 
	}
	
   public void stop() {
	   	mPlayerSD.stop();         
   }
   
   public void deleteFromSD(){
	   File file = new File(path);
       file.delete();
   }
}
